package com.zhuiYun.project.api.ordersAfterSales.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.zhuiYun.project.api.ordersAfterSales.entity.OrdersRetreat;
import com.zhuiYun.project.api.ordersAfterSales.mapper.ordersRetreatMapper;
import com.zhuiYun.project.api.ordersAfterSales.service.ordersRetreatService;
import com.zhuiYun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service

public class ordersRetreatServiceImpl implements ordersRetreatService {

    @Autowired
    ordersRetreatMapper ordersretreatMapper;





    @Override
    public PageResult ordersRetreatLirt(PageRequest pageResult, Integer userId) {

        List<OrdersRetreat> afterSalesList = ordersretreatMapper.getMyAllOrderAfterSales();

        PageHelper.startPage(pageResult.getPageNum(),pageResult.getPageSize());
        int pageNum = pageResult.getPageNum();
        List<OrdersRetreat> list = new ArrayList<>();
        List<OrdersRetreat> diyList = new ArrayList<>();

// 便利afterSalesList
        for (OrdersRetreat orderVO : afterSalesList){
            if(orderVO.getOrderTypeId() == 1 ){
                list.addAll(ordersretreatMapper.getMyCommodityOrderAfterSales());
            }
            if(orderVO.getOrderTypeId() == 2 ){
                diyList.addAll(ordersretreatMapper.getMyDiyOrderAfterSales());
            }
        }

        for(OrdersRetreat o :afterSalesList){
            o.setAddress(o.getAddressLocationProvince()+o.getAddressLocationCity()+o.getAddressLocationCounty()+o.getAddressDetailed());
        }

// 将diy商品商品list放进商品的list里
        afterSalesList.addAll(list);
        afterSalesList.addAll(diyList);
        return MybatisPageHelper.getPageResult(afterSalesList);
    }



    /**
     * @Author 小江
     * @Description //TODO 商品驳回信息全查
     * @Date 14:21 2023/4/25
     **/
    @Override
    public PageResult ordersRetreatComm(Integer userId, PageRequest pageResult) {
        PageHelper.startPage(pageResult.getPageNum(),pageResult.getPageSize());
        int pageNum = pageResult.getPageNum();

        List<OrdersRetreat> ordersRetreats = ordersretreatMapper.getMyCommodityOrderAfterSales();
        for(OrdersRetreat o :ordersRetreats){
            o.setAddress(o.getAddressLocationProvince()+o.getAddressLocationCity()+o.getAddressLocationCounty()+o.getAddressDetailed());
        }
        return MybatisPageHelper.getPageResult(ordersRetreats);
    }

    
    
    /**
     * @Author 小江
     * @Description //TODO diy订单驳回信息全查
     * @Date 14:50 2023/4/25
     **/
    @Override
    public PageResult ordersRetreatDiy(Integer userId, PageRequest pageResult) {
        PageHelper.startPage(pageResult.getPageNum(),pageResult.getPageSize());
        int pageNum = pageResult.getPageNum();

        List<OrdersRetreat> ordersRetreats = ordersretreatMapper.getMyDiyOrderAfterSales();
        for(OrdersRetreat o :ordersRetreats){
            o.setAddress(o.getAddressLocationProvince()+o.getAddressLocationCity()+o.getAddressLocationCounty()+o.getAddressDetailed());
        }
        return MybatisPageHelper.getPageResult(ordersRetreats);
    }

    
    
    /**
     * @Author 小江
     * @Description //TODO 修改驳回信息
     * @Date 15:02 2023/4/25
     **/
    @Override
    public int goodbyeDiy(Integer id) {
        OrdersRetreat ordersRetreat = new OrdersRetreat();
        ordersRetreat.setId(id);
        ordersRetreat.setOrdersStatusId(4);
        int i = ordersretreatMapper.updateByPrimaryKeySelective(ordersRetreat);
        return i;
    }

    @Override
    public int amendUpdate(OrdersRetreat ordersRetreat) {
        OrdersRetreat ordersRetreats = new OrdersRetreat();
        ordersRetreat.setOrdersStatusId(6);
        int i = ordersretreatMapper.updateByPrimaryKeySelective(ordersRetreat);
        return i;
    }


}
